<template>
  <div class="main" ref="main" style="width: 400px; height: 300px"></div>
</template>

<script>
import * as echarts from "echarts";

export default {
  props: ["shuju"],
  name: "StaTe",
  data() {
    return {
      datas: [],
    };
  },
  watch: {
    shuju: {
      deep: true,
      // immediate: true,
      handler(value) {
        let label = value[1].label;
        let values = value[1].value;
        this.datas = label.map((item, index) => {
          return {
            name: item,
            value: values[index],
          };
        });
        // console.log(this.datas);
        this.into();
      },
    },
  },
  methods: {
    into() {
      let shuju = {
        title: {
          text: "设备状态汇总",

          left: "center",
        },
        tooltip: {
          trigger: "item",
        },

        series: [
          {
            name: "Access From",
            type: "pie",
            radius: "60%",
            data: this.datas,
            // [
            //   { value: 100, name: "1" },
            //   { value: 735, name: "2" },
            //   { value: 580, name: "3" },
            //   { value: 484, name: "4" },
            // ]
            emphasis: {
              itemStyle: {
                shadowBlur: 100,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(this.$refs["main"]);
      // 绘制图表
      myChart.setOption(shuju);
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.into();
      // console.log(this);
    });
  },
};
</script>

<style scoped lang="less">
.main {
  background: #f3f3f3;
  border-radius: 20px;
  padding-top: 50px;
}
</style>